﻿          @{
    //结算
    Layout = null;
}
<link href="~/Content/CityChoice/css/chosen.min.css" rel="stylesheet" />
<link href="~/bootstrapvalidator-master/dist/css/bootstrapValidator.min.css" rel="stylesheet" />

<script src="~/Content/CityChoice/js/chosen.jquery.min.js"></script>
<script src="~/Content/CityChoice/js/area_chs.js"></script>
<script src="~/bootstrapvalidator-master/dist/js/bootstrapValidator.min.js"></script>
<script src="~/bootstrapvalidator-master/dist/js/language/zh_CN.js"></script>



<form id="CreateOrder" method="post" class="form-horizontal" action="CreateOrder" enctype="multipart/form-data">
    <div class="form-group">
        <label class="col-lg-2 control-label text-left">真实姓名:</label>
        <div class="col-lg-4">
            <input type="text" class="form-control" name="UName" id="UName" placeholder="真实姓名" />
        </div>
    </div>
    <div class="form-group">
        <label class="col-lg-2 control-label text-left">手机号:</label>
        <div class="col-lg-4">
            <input type="text" class="form-control" name="Tel" id="Tel" placeholder="手机号" />
        </div>
    </div>
    <div class="form-group">
        <label class="col-lg-2 control-label text-left">支付方式</label>
        <div class="radio col-lg-3">
            <label>
                <input type="radio" name="optionsRadios" id="optionsRadios1"value="option1" checked>在线支付
            </label>
        </div>
    </div>
    <div class="page-header">
        <h1>
            <small>订单总金额:@ViewBag.MoneyTotal 元</small>
            <input type="button" value="下一步" class="btn btn-primary" style="float:right;" id="Order"  data-loading-text="加载中..." autocomplete="off"/>
        </h1>
    </div>
</form>

<script>
    $("#Order").click(function () {
        var country = $("#country").val();
        var province = $("#province").val();
        var city = $("#city").val();
        var Address = $("#Address").val();
        var UName = $("#UName").val();
        var Tel = $("#Tel").val();
        var IDCard = $("#IDCard").val();
        if (province == "0")
        {
            province = "";
        }
        if (city == "0") {
            city = "";
        }
        Address = country + province + city + Address;



        $("#CreateOrder").bootstrapValidator('validate');
        if ($("#CreateOrder").data("bootstrapValidator").isValid() == true) {

            var $Btn = $(this).button('loading');
            setTimeout(function () { $Btn.button('reset'); }, 2000);
            $.ajax({
                cache: false,
                type: 'post',
                url: '@Url.Action("_OrderPay")',
                data: { Address: Address, Tel: Tel, UName: UName, IDCard: IDCard },
                dataType: 'text',
                success: function (data) {
                    $(this).button('reset');
                    if (data == 'NO') {
                        alert("生成失败，请联系管理员");
                    }
                    if (data == "User")
                    {
                        alert("无效的用户状态，请重新登陆");
                        location.href = "@Url.Action("UsersLogin","User")";
                        return false;
                    }
                    else {
                        $("#Car").html(data);
                    }
                },
                error: function () {
                    alert("Ajax调用出错请与管理员联系");

                }
            });
        }
    });
    $(document).ready(function () {
        $('#CreateOrder')
            .bootstrapValidator({
                message: 'This value is not valid',
                feedbackIcons: {
                    valid: 'glyphicon glyphicon-ok',
                    invalid: 'glyphicon glyphicon-remove',
                    validating: 'glyphicon glyphicon-refresh'
                },
                fields: {
                    UName: {
                        validators: {
                            notEmpty: {
                                message: '真实姓名不能为空'
                            }
                        }
                    },
                    Tel: {
                        validators: {
                            notEmpty: {
                                message: '手机号不能为空'
                            },
                             regexp: {
                                regexp: /^1(3|4|5|7|8)\d{9}$/,
                                message: '手机号格式不正确'
                            }
                        }
                    }
                    //,
                    //IDCard: {
                    //    validators: {
                    //        notEmpty: {
                    //            message: '身份证号不能为空'
                    //        },
                    //        regexp: {
                    //            regexp: /(^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$)|(^[1-9]\d{5}\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{2}$)/,
                    //            message: '身份证号不能为空'
                    //        }
                    //    }
                    //}
                }
            });
    });
</script>



<script type="text/javascript">

    var areaObj = [];
    function initLocation(e) {
        var a = 0;
        for (var m in e) {
            areaObj[a] = e[m];
            var b = 0;
            for (var n in e[m]) {
                areaObj[a][b++] = e[m][n];
            }
            a++;
        }
    }
</script>

<script src="~/Content/CityChoice/js/location_chs.js"></script>
<script type="text/javascript">
    var country = '';
    for (var a = 0; a <= _areaList.length - 1; a++) {
        var objContry = _areaList[a];
        country += '<option value="' + objContry + '" a="' + (a + 1) + '">' + objContry + '</option>';
    }
    $("#country").html(country).chosen().change(function () {
        var a = $("#country").find("option[value='" + $("#country").val() + "']").attr("a");
        var _province = areaObj[a];
        var province = '';
        for (var b in _province) {
            var objProvince = _province[b];
            if (objProvince.n) {
                province += '<option value="' + objProvince.n + '" b="' + b + '">' + objProvince.n + '</option>';
            }
        }
        if (!province) {
            province = '<option value="0" b="0">------</option>';
        }
        $("#province").html(province).chosen().change(function () {
            var b = $("#province").find("option[value='" + $("#province").val() + "']").attr("b");
            var _city = areaObj[a][b];
            var city = '';
            for (var c in _city) {
                var objCity = _city[c];
                if (objCity.n) {
                    city += '<option value="' + objCity.n + '">' + objCity.n + '</option>';
                }
            }
            if (!city) {
                var city = '<option value="0">------</option>';
            }
            $("#city").html(city).chosen().change();
            $(".dept_select").trigger("chosen:updated");
        });
        $("#province").change();
        $(".dept_select").trigger("chosen:updated");
    });
    $("#country").change();
</script>

